package init

import (
	"fmt"
	"github.com/fsnotify/fsnotify"
	"github.com/spf13/viper"
	"user-srv/basic/config"
)

func InitsConfig() {
	viper.SetConfigFile("../../config.yaml")
	viper.ReadInConfig()
	viper.Unmarshal(&config.Config)
	fmt.Println(config.Config)
	//开启viper配置热更新
	viper.WatchConfig()
	viper.OnConfigChange(func(in fsnotify.Event) {
		err := viper.Unmarshal(&config.Config)
		if err != nil {
			fmt.Println("配置热更新启动失败", config.Config)
			return
		}
		fmt.Println("配置热更新启动成功", config.Config)
	})
}
